<template>
  <div class="Cabinets_Box">
    <div class="Cabinets_titleBox">
      <div class="titleBox1_l">
        <div class="Title_icon"></div>
        <span class="public_Text">成人九病区药疗室药柜</span>
      </div>
      <!-- <div class="zhuangtai_box zaixian lixian"></div> -->
      <div class="titleBox1_r" @click="addClose"></div>
    </div>
    <div class="Cabinets_TopC">
      <div class="TopC_btn" :class="CabinetsAct == 1 ? 'TopcBeijAct' : 'TopcBeij'" @click="addCabinets(1)">
        <span class="TopSpan" :class="CabinetsAct == 1 ? 'TopSpan1' : ''">药柜物品</span>
      </div>
      <div class="TopC_btn" :class="CabinetsAct == 2 ? 'TopcBeijAct' : 'TopcBeij'" @click="addCabinets(2)">
        <span class="TopSpan" :class="CabinetsAct == 2 ? 'TopSpan1' : ''">缺货提醒</span>
      </div>
      <div class="TopC_btn" :class="CabinetsAct == 3 ? 'TopcBeijAct' : 'TopcBeij'" @click="addCabinets(3)">
        <span class="TopSpan" :class="CabinetsAct == 3 ? 'TopSpan1' : ''">临期提醒</span>
      </div>
    </div>
    <div class="Cabinets_BomC">
      <div class="Cabinets_BomCItem" v-for="item in shujvList"
        :class="rtnCabinetsName(item.curLow,item.nearDate,item.expiredDate)">
        <div class="BomCItem_1">{{item?.medName}}</div>
        <div class="BomCItem_2">
          <div class="BomCItem_2L">规格: {{item?.specs}}</div>
          <div class="BomCItem_2R">库存: {{item?.cur + item?.units}}</div>
        </div>
        <!-- <div class="BomCItem_3">
          <div class="BomCItem_3L">生产日期: 2004/05/22</div>
          <div class="BomCItem_3R">保质期至 : 2004/05/22</div>
        </div> -->
      </div>
    </div>
  </div>
</template>
<script setup>
  import { ref, watch } from "vue"
  import { postygdatajApi, postygoutofstockjApi, postygjnearApi } from "@/api/index.js";
  const props = defineProps({
    yaoGuiObj: {
      type: Object,
      default: true
    }
  })
  const emit = defineEmits(["clsoeCabinets"])
  const addClose = () => {
    emit("clsoeCabinets")
  }
  const CabinetsAct = ref(1)
  const addCabinets = (e) => {
    CabinetsAct.value = e
    init(TijiaoList.value, e)
  }
  const shujvList = ref([])
  const init = async (data, qiehuan) => {
    // console.log(data.DevicesId, '方法接受到了数据', qiehuan);
    // let TijaoObj = {
    //   deviceId: data.DevicesId
    // }
    if (qiehuan == 1) {
      const res = await postygdatajApi(data.DevicesId)
      // console.log(res.data.data, '查询药柜全部药品列表');
      shujvList.value = res.data.data
    } else if (qiehuan == 2) {
      const res = await postygoutofstockjApi(data.DevicesId)
      // console.log(res.data.data, '查询药柜全部药品列表');
      shujvList.value = res.data.data
    } else if (qiehuan == 3) {
      const res = await postygjnearApi(data.DevicesId)
      // console.log(res.data.data, '查询药柜全部药品列表');
      shujvList.value = res.data.data
    }

  }
  const rtnCabinetsName = (a, b, c) => {
    console.log(a, b, c);
    let className = ""
    if (a == 0 && b == 0 && c == 0) {
      // 正常
      className = 'Cabinets_BomCItem'
    } else if (a == 1 && b == 0 && c == 0) {
      // 缺货
      className = 'Cabinets_BomCItemquehuo'
    } else if (a == 0 && b == 1 && c == 0) {
      // 临期
      className = 'Cabinets_BomCItemlinqi'
    } else if (a == 0 && b == 0 && c == 1) {
      // 过期
      className = 'Cabinets_BomCItemlinqi'
    }
    return className
  }
  const TijiaoList = ref({})
  watch(
    () => props.yaoGuiObj,
    (val) => {
      TijiaoList.value = val
      console.log(val, "监听到了药柜的变化")
      init(val, CabinetsAct.value)
    },
    {
      deep: true,
      immediate: true
    }
  )
</script>
<style scoped lang="less">
  .Cabinets_Box {
    width: 100%;
    height: 100%;
    background: url("@/assets/accessControl/changbeijing.png") no-repeat center;
    background-size: 100% 100%;

    .zaixian {
      background: url("@/assets/ultraviolet/zaixian.png") no-repeat center;
      background-size: 100% 100%;
    }

    .lixian {
      background: url("@/assets/ultraviolet/lixian.png") no-repeat center;
      background-size: 100% 100%;
    }

    .zhuangtai_box {
      width: 160px;
      height: 52px;
    }

    .Cabinets_titleBox {
      width: 808px;
      height: 60px;
      position: absolute;
      left: 50%;
      top: 20px;
      transform: translate(-50%, 0);
      display: flex;
      align-items: center;
      justify-content: space-between;

      .titleBox1_l {
        width: 600px;
        height: 60px;
        display: flex;
        align-items: center;

        .Title_icon {
          margin-left: 20px;
          width: 50px;
          height: 50px;
          background: url("@/assets/Cabinets/tubiao.png") no-repeat center;
          background-size: 100% 100%;
        }

        span {
          margin-left: 20px;
        }
      }

      .titleBox1_r {
        cursor: pointer;
        width: 80px;
        height: 80px;
        background: url("@/assets/PatientInformation/xhao.png") no-repeat center;
        background-size: 100% 100%;
      }
    }

    .Cabinets_TopC {
      width: 808px;
      height: 72px;
      position: absolute;
      left: 50%;
      top: 120px;
      transform: translate(-50%, 0);
      display: flex;
      align-items: center;

      .TopSpan {
        font-size: 30px;
        font-weight: 600;
        background: linear-gradient(180deg, #00d0ff 0%, #0073ff 100%);
        background-clip: text;
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
      }

      .TopSpan1 {
        font-size: 30px;
        font-weight: 600;
        background: linear-gradient(180deg, #fff 0%, #bef2ff 100%);
        background-clip: text;
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
      }

      .TopC_btn {
        cursor: pointer;
        width: 184px;
        height: 72px;
        background-color: pink;
        margin-right: 20px;
        text-align: center;
        line-height: 72px;
      }

      .TopcBeij {
        border-radius: 12px;
        background: linear-gradient(180deg, #fff 0%, #8accff 100%);
        box-shadow: 0 0 12px 2px rgba(0, 89, 255, 0.3) inset;
      }

      .TopcBeijAct {
        border-radius: 12px;
        background: linear-gradient(180deg, #005bee 0%, #00d1f6 100%);

        box-shadow: 0 -3px 10px 1px #fff inset;
        backdrop-filter: blur(5px);
      }
    }

    .Cabinets_BomC {
      width: 808px;
      height: 1195px;
      position: absolute;
      left: 50%;
      top: 220px;
      transform: translate(-50%, 0);
      // display: flex;
      overflow-y: scroll;

      .Cabinets_BomCItem {
        margin-bottom: 30px;
        width: 100%;
        height: 174px;
        border-radius: 20px;
        border: 1px solid #90a7be;
        background: linear-gradient(90deg, #fdfdfd 0%, #f9fcff 100%);
        display: flex;
        flex-wrap: wrap;
        align-items: center;
      }

      .Cabinets_BomCItemquehuo {
        margin-bottom: 30px;
        width: 100%;
        height: 174px;
        border-radius: 20px;
        border: 1px solid #ffc038;
        background: linear-gradient(90deg, #fffdfa 0%, #fff7ec 100%);
        display: flex;
        flex-wrap: wrap;
        align-items: center;
      }

      .Cabinets_BomCItemlinqi {
        margin-bottom: 30px;
        width: 100%;
        height: 174px;
        border-radius: 20px;
        border: 1px solid #fc6832;
        background: linear-gradient(90deg, #fff7f4 0%, #fff3f0 100%);
        display: flex;
        flex-wrap: wrap;
        align-items: center;
      }

      .BomCItem_1 {
        margin: auto;
        width: 95%;
        height: 42px;
        color: #000;
        font-family: "PingFang SC";
        font-size: 30px;
        font-weight: 600;
      }

      .BomCItem_2 {
        margin: auto;
        width: 95%;
        height: 42px;
        display: flex;
        color: #000;
        font-family: "PingFang SC";
        font-size: 30px;
        font-weight: 400;

        .BomCItem_2L {
          width: 50%;
          text-align: left;
        }

        .BomCItem_2R {
          width: 50%;
          text-align: right;
        }
      }

      .BomCItem_3 {
        margin: auto;
        width: 95%;
        height: 42px;
        display: flex;
        color: rgba(0, 0, 0, 0.6);
        font-family: "PingFang SC";
        font-size: 30px;
        font-style: normal;
        font-weight: 400;
        line-height: normal;

        .BomCItem_3L {
          width: 50%;
          text-align: left;
        }

        .BomCItem_3R {
          width: 50%;
          text-align: right;
        }
      }
    }
  }
</style>